namespace JQuery.WebKit
{
    using System.ComponentModel;
    using System.Security.Permissions;
    using System.Web;
    using System.Web.UI;

    [TypeConverter(typeof(ExpandableObjectConverter)), AspNetHostingPermission(SecurityAction.LinkDemand, Level=AspNetHostingPermissionLevel.Minimal), AspNetHostingPermission(SecurityAction.InheritanceDemand, Level=AspNetHostingPermissionLevel.Minimal)]
    public sealed class GroupSettings : IStateManager
    {
        private GroupFieldCollection _groupFields;
        private bool _isTracking;
        private StateBag _viewState = new StateBag();

        void IStateManager.LoadViewState(object state)
        {
            if (state != null)
            {
                ((IStateManager) this.ViewState).LoadViewState(state);
            }
        }

        object IStateManager.SaveViewState()
        {
            return ((IStateManager) this.ViewState).SaveViewState();
        }

        void IStateManager.TrackViewState()
        {
            this._isTracking = true;
            ((IStateManager) this.ViewState).TrackViewState();
        }

        public override string ToString()
        {
            return string.Empty;
        }

        [Description("The initial state of the groups - collapsed or expanded."), DefaultValue(false), NotifyParentProperty(true), Category("Behavior")]
        public bool CollapseGroups
        {
            get
            {
                return ((this.ViewState["CollapseGroups"] != null) && ((bool) this.ViewState["CollapseGroups"]));
            }
            set
            {
                this.ViewState["CollapseGroups"] = value;
            }
        }

        [Category("Behavior"), DefaultValue((string) null), PersistenceMode(PersistenceMode.InnerProperty), NotifyParentProperty(true), Description("The list of fields that take part in grouping")]
        public GroupFieldCollection GroupFields
        {
            get
            {
                if (this._groupFields == null)
                {
                    this._groupFields = new GroupFieldCollection();
                    ((IStateManager) this._groupFields).TrackViewState();
                }
                return this._groupFields;
            }
        }

        bool IStateManager.IsTrackingViewState
        {
            get
            {
                return this._isTracking;
            }
        }

        private StateBag ViewState
        {
            get
            {
                return this._viewState;
            }
        }
    }
}

